package com.ruoyi.zhmk.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zhmk.domain.ZhmkCarsend;
import com.ruoyi.zhmk.service.IZhmkCarsendService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆下发Controller
 * 
 * @author sxl
 * @date 2021-06-10
 */
@Controller
@RequestMapping("/zhmk/carsend")
public class ZhmkCarsendController extends BaseController
{
    private String prefix = "zhmk/carsend";

    @Autowired
    private IZhmkCarsendService zhmkCarsendService;

    @RequiresPermissions("zhmk:carsend:view")
    @GetMapping()
    public String carsend()
    {
        return prefix + "/carsend";
    }

    /**
     * 首页展示车辆出入信息
     * @return
     */
    @RequiresPermissions("zhmk:carsend:view")
    @GetMapping("/carIndex")
    public String carIndex()
    {
        return prefix + "/carIndex";
    }

    /**
     * 查询车辆下发列表
     */
    @RequiresPermissions("zhmk:carsend:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZhmkCarsend zhmkCarsend)
    {
        startPage();
        List<ZhmkCarsend> list = zhmkCarsendService.selectZhmkCarsendList(zhmkCarsend);
        return getDataTable(list);
    }

    /**
     * 导出车辆下发列表
     */
    @RequiresPermissions("zhmk:carsend:export")
    @Log(title = "车辆下发", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZhmkCarsend zhmkCarsend)
    {
        List<ZhmkCarsend> list = zhmkCarsendService.selectZhmkCarsendList(zhmkCarsend);
        ExcelUtil<ZhmkCarsend> util = new ExcelUtil<ZhmkCarsend>(ZhmkCarsend.class);
        return util.exportExcel(list, "车辆下发数据");
    }

    /**
     * 新增车辆下发
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存车辆下发
     */
    @RequiresPermissions("zhmk:carsend:add")
    @Log(title = "车辆下发", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZhmkCarsend zhmkCarsend)
    {
        return toAjax(zhmkCarsendService.insertZhmkCarsend(zhmkCarsend));
    }

    /**
     * 修改车辆下发
     */
    @GetMapping("/edit/{carsendId}")
    public String edit(@PathVariable("carsendId") Long carsendId, ModelMap mmap)
    {
        ZhmkCarsend zhmkCarsend = zhmkCarsendService.selectZhmkCarsendById(carsendId);
        mmap.put("zhmkCarsend", zhmkCarsend);
        return prefix + "/edit";
    }

    /**
     * 修改保存车辆下发
     */
    @RequiresPermissions("zhmk:carsend:edit")
    @Log(title = "车辆下发", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZhmkCarsend zhmkCarsend)
    {
        return toAjax(zhmkCarsendService.updateZhmkCarsend(zhmkCarsend));
    }

    /**
     * 删除车辆下发
     */
    @RequiresPermissions("zhmk:carsend:remove")
    @Log(title = "车辆下发", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zhmkCarsendService.deleteZhmkCarsendByIds(ids));
    }
}
